package com.sdry.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.List;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.sdry.model.lz.CodeMark;

/**
 * 
 * @Title:GsonClass
 * @Package com.sdry.web.controller.llm
 * @author llm
 * @date 2019年12月18日
 * @version 1.0
 */
public class GsonClass {

	public static void main(String[] args) {

		share();
	}

	public static String txt2String(File file) {
		StringBuilder result = new StringBuilder();
		try {
			BufferedReader br = new BufferedReader(new FileReader(file));// 构造一个BufferedReader类来读取文件
			String s = null;
			while ((s = br.readLine()) != null) {// 使用readLine方法，一次读一行
				result.append(System.lineSeparator() + s);
			}
			br.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result.toString();
	}

	public static void share() {
		Gson gson = new Gson();
//		System.out.println(txt2String(new File("C:\\Users\\Administrator\\Desktop\\华缘\\离线文件\\offline (1).txt")));
		List<String> string = gson.fromJson(txt2String(new File("C:\\Users\\Administrator\\Desktop\\华缘\\离线文件\\offline (1).txt")), new TypeToken<List<String>>() {
		}.getType());
		for (String s : string) {
			List<CodeMark> codemark = gson.fromJson(s, new TypeToken<List<CodeMark>>() {
			}.getType());
			for (CodeMark c : codemark) {
				c.getCode().toString();
				System.out.println(c.getCode());
			}
		}
	}
}
